const install = (Vue, vm) => {
  Vue.prototype.$u.http.setConfig({
    // baseUrl: 'https://flzx.nanjingyunpeng.cn',
    baseUrl: "https://www.xingmuning.com",
    showLoading: true,
    dataType: '',
    loadingMask: true,
    loadingText: '努力加载中~',
    loadingTime: 800,
    originalData: true,
    header: {
      'content-type': 'application/x-www-form-urlencoded',
    }
  });
  Vue.prototype.$u.http.interceptor.request = (config) => {
    config.header.token = uni.getStorageSync('token')
    return config;
  }
  Vue.prototype.$u.http.interceptor.response = (res) => {
    if (res.data.code == 1) {
      // if (res.data.msg !== null) {
      // 	vm.$u.toast(res.data.msg);
      // }
      return res.data;
    } else if (res.data.code == 0) {
      vm.$u.toast(res.data.msg);
      return false;
    } else if (res.data.code == 401) {
      vm.$u.toast(res.data.msg);
      uni.clearStorage();
      setTimeout(() => {
        uni.reLaunch({
          url: '/pages/user-login/user-login'
        })
      }, 1500)
      return false;
    } else if (res.statusCode == 500) {
      vm.$u.toast('请求错误');
      return false;
    } else {
      return false;
    }
  }
}

export default {
  install
}